
#include "StandartSubscribers.h"
#include "PublisherBase.h"

using namespace ttg::services;

//------------------------
//--- UpdateSubscriber ---
//------------------------

UpdateSubscriber::UpdateSubscriber()
{
	this->step = 0.0f;
	PublisherBase::getRef()->subscribeAsSoonAsPossible("WORLD_UPDATE", this, processWorldUpdate);
}

void UpdateSubscriber::processWorldUpdate(Subscriber *s, Event *ev)
{
#ifdef TTG_DEBUG
	UpdateSubscriber *us = dynamic_cast<UpdateSubscriber *>(s);
	UpdateEvent *ue = dynamic_cast<UpdateEvent *>(ev);
#else
	UpdateSubscriber *us = static_cast<UpdateSubscriber *>(s);
	UpdateEvent *ue = static_cast<UpdateEvent *>(ev);
#endif
	if (us == NULL || ue == NULL)
		throw Error(Error::FATAL, "UpdateSubscriber", "processWorldUpdate",
					"Cannot cast params");
	us->step = ue->getStep();
};